package nil.ed.simulator.request.ui.jfx.event;

import javafx.collections.ObservableList;
import nil.ed.simulator.request.biz.qq.scheduler.QqLoginScheduleUnit;
import nil.ed.simulator.request.enums.events.EventType;
import nil.ed.simulator.request.event.Event;
import nil.ed.simulator.request.event.bus.EventListener;
import nil.ed.simulator.request.ui.jfx.bean.qq.QQRow;
import nil.ed.simulator.request.ui.jfx.controller.TableViewController;
import nil.ed.simulator.request.ui.jfx.manager.ControllerManager;

/**
 * @author lidelin.
 */
public class QqTaskFinishListener implements EventListener {

    @Override
    public void onEvent(Event event) {
        QqLoginScheduleUnit unit = (QqLoginScheduleUnit) event.getData();
        TableViewController tableViewController = ControllerManager.getTable();
        ObservableList<Object> dataList = tableViewController.getDataList();
        for (Object obj : dataList) {
            QQRow qqRow = ((QQRow) obj);
            if (qqRow.getQqItem() == unit.getQqItem()) {
                qqRow.setTaskStatus(QQRow.TASK_STATUS_SUCCESS);
                return;
            }
        }
        // todo not find
    }

    @Override
    public boolean isSupport(Event event) {
        return event.getData() instanceof QqLoginScheduleUnit && event.getEventType() == EventType.SCHEDULER_FINISH;
    }
}
